package com.bootdo.common.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import com.aliyuncs.exceptions.ClientException;
import com.bootdo.system.controller.SmsController;

public class RandomUtils {

	private static final String KEY = "abc123"; // KEY为自定义秘

	public static Map<String, Object> sendSms(String phone) {
		Random random = new Random();
		Integer randomNum = (1000 + random.nextInt(9000));
		String srandom = Integer.toString(randomNum);
		// 生成5分钟后时间，用户校验是否过期
		Map<String, Object> resultMap;
		try {
			SmsController.sendSms(phone, srandom);
			resultMap = new HashMap<>();
			resultMap.put("code", srandom);
			resultMap.put("msg", "发送成功");
			return resultMap;
		} catch (ClientException e) {
			// TODO Auto-generated catch block
			return R.error("发送失败");

		}

	}

	public static String codeNum() {
		Random random = new Random();
		Integer randomNum = (1000 + random.nextInt(9000));
		String srandom = Integer.toString(randomNum);
		return srandom;

	}

	// 生成十位数奖品兑换码
	public static String code(){
		int count = 4;
		String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		StringBuilder sb = new StringBuilder();
		Random r = new Random(System.currentTimeMillis());
		for (int i = 0; i < count; i++) {
			int d = r.nextInt(62);
			sb.append(str.charAt(d));
		}
		return sb.toString();
	}
	
	
   
	
}
